<?php
require_once('common.php');
//************************执行代码开始*************************

$uid=is_numeric($_GET['uid'])?$_GET['uid']:'0';
if($_GET['do']=='del'){
	$db->query("delete from {$prefix}users where uid='$uid'");
	echo "<script language='javascript'>alert('删除成功！');window.location.href='ulist.php';</script>";
}elseif($_GET['do']=='dell'){
	$db->query("delete from {$prefix}users where vip='0'");
	echo "<script language='javascript'>alert('删除成功！');window.location.href='ulist.php';</script>";
}elseif($_GET['do']=='daili'){
	if($uid && $row=$db->get_row("select daili from {$prefix}users where uid='$uid'")){
		if($row['daili']){
			$db->query("update {$prefix}users set daili=0 where uid='{$uid}'");
			echo "<script language='javascript'>alert('取消代理成功！');window.location.href='ulist.php';</script>";
		}else{
			$db->query("update {$prefix}users set daili=1 where uid='{$uid}'");
			echo "<script language='javascript'>alert('设为代理成功！');window.location.href='ulist.php';</script>";
		}
	}
}elseif($_GET['do']=='fuzhan'){
	if($uid && $row=$db->get_row("select fuzhan from {$prefix}users where uid='$uid'")){
		if($row['fuzhan']){
			$db->query("update {$prefix}users set fuzhan=0 where uid='{$uid}'");
			echo "<script language='javascript'>alert('取消副站长成功！');window.location.href='ulist.php';</script>";
		}else{
			$db->query("update {$prefix}users set fuzhan=1 where uid='{$uid}'");
			echo "<script language='javascript'>alert('设为副站长成功！');window.location.href='ulist.php';</script>";
		}
	}
}

$p=is_numeric($_GET['p'])?$_GET['p']:'1';
$pp=$p+8;
$pagesize=12;
$start=($p-1)*$pagesize;

if($_GET['do']=='search' && $s=safestr($_GET['s'])){
	$pagedo='seach';
	$users=$db->get_results("select * from {$prefix}users where uid='{$s}' or user like'%{$s}%' order by (case when uid='{$s}' then 8 else 0 end)+(case when user like '%{$s}%' then 3 else 0 end) desc limit 20");
}else{
	$pages=ceil(get_count('users','1=1','uid')/$pagesize);
	$users=$db->get_results("select * from {$prefix}users order by uid desc limit $start,$pagesize");
}
if($_GET['c']=="daili")$users=$db->get_results("select * from {$prefix}users where daili='1' order by uid desc limit $start,$pagesize");
if($_GET['c']=="fuzhan")$users=$db->get_results("select * from {$prefix}users where fuzhan='1' order by uid desc limit $start,$pagesize");
if($pp>$pages) $pp=$pages;
if($p==1){
	$prev=1;
}else{
	$prev=$p-1;
}
if($p==$pages){
	$next=$p;
}else{
	$next=$p+1;
}

//************************执行代码结束**************************
C('pageid','adminuser');
C('webtitle','用户列表');
include_once 'common.head.php';
?>
<div class="wrapper wrapper-content animated fadeInRight">
              <!-- page start--><!-- 网站设置 -->
                      <div class="row">
            <div class="col-sm-12">
			<form action="?" method="GET">
		<div class="input-group">
		<input type="hidden" name="do" value="search">
		<input type="text" name='s' placeholder="用户uid、用户名" class="form-control">
		<span class="input-group-btn">
		<input type="submit" class="btn btn-primary" value="搜索">
		</span>
		</div>
		</form>
		</div><hr>
		<div class="col-sm-6">
		<form action="?" method="GET">
		<div class="input-group">
		<input type="hidden" name="do" value="daili">
		<input type="text" name='uid' placeholder="用户uid" class="form-control">
		<span class="input-group-btn">
		<input type="submit" class="btn btn-primary" value="设为代理">
		</span>
		</div>
		</form>
		</div>
		<div class="col-sm-6">
		<form action="?" method="GET">
		<div class="input-group">
		<input type="hidden" name="do" value="fuzhan">
		<input type="text" name='uid' placeholder="用户uid" class="form-control">
		<span class="input-group-btn">
		<input type="submit" class="btn btn-primary" value="设为副站长">
		</span>
		</div>
		</form>
		</div><hr/>
		</div>
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>用户列表 </h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
				<?php if($users){foreach($users as $user){?>
				<div class="col-xs-12 col-md-3">
					<div class="list-group">
						<h4 class="list-group-item list-group-item-info"><a href="uset.php?xz=update&uid=<?=$user[uid]?>">UID:<?=$user[uid]?> [编辑]</a><a href="?do=del&p=<?=$p?>&uid=<?=$user[uid]?>" onClick="if(!confirm('确认删除用户:<?=$user[user]?>')){return false;}"><span class="glyphicon glyphicon-remove" aria-hidden="true" style="float:right;"></span></a></h4>
						<div class="list-group-item">
							<span class="glyphicon glyphicon-user" aria-hidden="true">&nbsp;<?=$user[user]?></span>
						</div>
						<div class="list-group-item">
							<span class="glyphicon glyphicon-list" aria-hidden="true">&nbsp;<?php if(get_isvip($user[vip],$user[vipend])){ echo "<font color='green'>VIP用户</font>";}else{echo"免费用户";}?></span>
						</div>
						<div class="list-group-item">
							<span class="glyphicon glyphicon-yen" aria-hidden="true">&nbsp;<font color="red" size="3"><?=$user[rmb]?></font>&nbsp;元</span>
						</div>
						<div class="list-group-item">
							<span class="glyphicon glyphicon-th" aria-hidden="true">&nbsp;配额：<?=$user[peie]?></span>
						</div>
						<div class="list-group-item">
							<span class="glyphicon glyphicon-comment" aria-hidden="true">&nbsp;QQ:<?=$user[qq]?></span>
						</div>
						<div class="list-group-item">
							<span class="glyphicon glyphicon-indent-right" aria-hidden="true">&nbsp;权限:
							<?php
							if($user[fuzhan]==1){
							echo '副站长 ';
							}
							if($user[daili]==1){
							echo '代理 ';
							}
							if($user[daili]==0 && $user[fuzhan]==0){
							echo '普通用户';
							}
							?></span>
						</div>
						<div class="list-group-item">
							<a href="?do=daili&p=<?=$p?>&uid=<?=$user[uid]?>" onClick="if(!confirm('确认更改？')){return false;}" class="btn btn-primary btn-outline btn-xs"><?php if($user[daili]){echo'取消代理';}else{echo'设为代理';}?></a>
							<a href="?do=fuzhan&p=<?=$p?>&uid=<?=$user[uid]?>" onClick="if(!confirm('确认更改？')){return false;}" class="btn btn-success btn-outline btn-xs"><?php if($user[fuzhan]){echo'取消副站长';}else{echo'设为副站长';}?></a>
						</div>
					</div>
				</div>
				<?php }}?>
			<?php if($pagedo!='seach'){?>
			<div class="row" style="text-align:center;">
			<div class="col-xs-12">
		<div class="list-group-item list-group-item-info">
			<ul class="pagination pagination-lg">
					<li <?php if($p==1){echo'class="disabled"';}?>><a href="?p=1">首页</a></li>
					<li <?php if($prev==$p){echo'class="disabled"';}?>><a href="?p=<?=$prev?>">&laquo;</a></li>
					<?php for($i=$p;$i<=$pp;$i++){?>
					<li <?php if($i==$p){echo'class="active"';}?>><a href="?p=<?=$i?>"><?=$i?></a></li>
					<?php }?>
					<li <?php if($next==$p){echo'class="disabled"';}?>><a href="?p=<?=$next?>">&raquo;</a></li>
					<li <?php if($p==$pages){echo'class="disabled"';}?>><a href="?p=<?=$pages?>">末页</a></li>
				</ul>
		</div>
	</div>
			</div>
			<?php }?>
		</div></div>
		</div>
	  <?php
include_once 'common.foot.php';
?>